package com.pdemo.front.resource;

import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.pdemo.core.entity.Borrower;
import com.pdemo.front.annotation.Authenticate;
import com.pdemo.front.service.BorrowerService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;


@Service
@Path("/borrower")
@Api(value = "/borrower", description = "Operations about borrower")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON})
@RolesAllowed("ROLE_ADMIN")
@Authenticate
public class BorrowerResource {
	
	
	@Autowired
	@Qualifier("borrowerService")
	private BorrowerService borrowerService;
	
	
	@GET
	@Path("/borrowers")
	@ApiOperation(value = "Get all the borrowers in the system", 
    notes = "Returns all the borrowers in the system", 
    response = Borrower.class)
	  @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
		      @ApiResponse(code = 404, message = "borrower not found") })
	public List<Borrower> getAllBorrowers(){
		return borrowerService.getAllBorrowers();
	}
	
	@POST
	@Path("/borrowers")
	public Long createBorrower(@Context HttpServletRequest request,Borrower borrower){
		return borrowerService.createBorrower(borrower);
	}

}
